//字符串的排列
import java.util.;

public class Solution {
    
      代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     
      
      @param str string字符串 
      @return string字符串ArrayList
     
    public ArrayListString Permutation (String str) {
         write code here
        SetString set = new HashSet();
        int len = str.length();
        char[] arr = str.toCharArray();
        boolean[] flag = new boolean[len];
        ArrayListString ret = new ArrayListString();
        fun(arr, flag, set, ret, new char[len], 0, len);
        return ret;
    }

    void fun(char[] arr, boolean[] flag, SetString set, ArrayListString ret, char[] tmp, int i, int len) {
        if (i == len) {
            StringBuilder s = new StringBuilder();
            for (int j = 0; j  i; j++) {
                s.append(tmp[j]);
            }
            String a = s.toString();
            if (!set.contains(a)) {
                ret.add(a);
                set.add(a);
            }
        }
        for (int j = 0; j  len; j++) {
            if (flag[j] == false) {
                flag[j] = true;
                tmp[i] = arr[j];
                fun(arr, flag, set, ret, tmp, i+1, len);
                flag[j] = false;
            }
        }
    }
}